package logic

import (
	"context"

	"game/rpc/gamerpc/game"
	"game/rpc/gamerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserLogic {
	return &GetUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUserLogic) GetUser(in *game.GetUserRequest) (*game.GetUserResponse, error) {
	// 根据用户ID查询用户
	user, err := l.svcCtx.UsersModel.FindOne(l.ctx, int64(in.Id))
	if err != nil {
		return nil, err
	}

	// 构造响应
	resp := &game.GetUserResponse{
		User: &game.User{
			Id:       user.Id,
			Username: user.Username,
			Email:    user.Email.String,
		},
	}

	return resp, nil
}
